home *** CD-ROM | disk | FTP | other *** search
/ 3D Images / 3D Images.iso / programs / amiga / batchfactory / scripts / opalpaint / opal_moving_brush < prev    next >
Encoding:
Text File  |  1995-01-12  |  8.9 KB  |  354 lines

  1. /* 
  2.                              OPAL MOVING BRUSH
  3.                                By J.L. White
  4.                           ©1994 Merlin's Software
  5.  
  6.            Load Images & Add A Moving Brush To Series Of Frames
  7.                              Opal Paint Script
  8.                       Requires The Rexxarplib.library
  9.  
  10.  Batch Factory Batch Conversion Scripts are basically Arexx scripts that
  11. allow you to pass certain parameters to the external program you wish
  12. to use to convert the images from one format to another. You can pass
  13. five different strings from Batch Factory to the script by using the
  14. following commands:
  15.  
  16. $N = This will pass the current selected filename.
  17. $P = This will tell Batch Factory to ask for a path to save new frames to.
  18. $# = This will pass the current frame number in the script.
  19. $T = This will pass the total number of frames in the script.
  20. $A = This will pass an offset number to be used to save frames with.
  21.  
  22. NOTE: The following line is required to work as a Batch Factory Script:
  23.  
  24. PARSE=$N $P $# $A $T
  25.  
  26. */
  27.  
  28. if ~show('l', "rexxarplib.library") then do
  29.     check = addlib('rexxsupport.library',0,-30,0) 
  30.     check = addlib('rexxarplib.library',0,-30,0)   
  31.     end
  32.  
  33. options results
  34. arg InPic OutPic FrameNum AddNum TotalNum
  35. SaveNum = FrameNum + AddNum
  36.  
  37. if FrameNum = 1 then do
  38.     Top = 170
  39.     Height = ScreenRows("Batch")
  40.     if Height < 400 then Top = 70
  41.     address "AREXX"
  42.     ScreenToFront("Batch")
  43.     call GetMotionPath
  44.     call Locate_OpalPaint
  45.     address "OpalPaint_Rexx"
  46.     SaveSetUp
  47.         SetPrefs 1024
  48.       AskBool "Select Save Format You Wish To Use?\n\n        Select [OK] For IFF \n\n     Select [CANCEL] For JPEG"
  49.     if Result=0 then do
  50.         AskProp 1 100 84 "Enter JPEG Compression Value (1 - 100)!"
  51.         Format = JPEG Result
  52.         end
  53.     else
  54.         Format = IFF
  55.            Saver Format
  56.     ActiveBrush 1
  57.     AskFileName 'Select Image To Use For Brush! RAM: '
  58.     LoadBrush result
  59.      AskBool "Do You Wish To Add A Shadow To Your Brush?"
  60.     if Result=0 then Answer = "NO"
  61.     else do
  62.         Answer = "YES"
  63.         AskProp 1 10 3 "Enter Shadow Depth (1 - 10)!"
  64.         Answer2 = result
  65.         Answer = "YES"
  66.         AskProp 1 100 19 "Enter Shadow Darkness (1 - 100)!"
  67.         Answer3 = result
  68.         end
  69.     Key "j"
  70.     call open TempFile,"Ram:OMB",W
  71.     call writeln TempFile,Answer
  72.     call writeln TempFile,Answer2
  73.     call writeln TempFile,Answer3
  74.     call close TempFile
  75.     end
  76. else do
  77.     call open TempFile,"Ram:OMB",R
  78.     line = readln(TempFile)
  79.     parse var line Answer
  80.     line = readln(TempFile)
  81.     parse var line Answer2
  82.     line = readln(TempFile)
  83.     parse var line Answer3
  84.     call close TempFile
  85.     end
  86.  
  87. address "OpalPaint_Rexx"
  88. ActiveColor 1
  89.  
  90. Load InPic
  91. PageSize
  92. MainPage = result
  93. parse var MainPage Width Height 
  94. ActiveBrush 1
  95. ColourSource MULTICOLOR
  96. HandleCenter
  97. call GetXYCords
  98. AntiAlias 1 100
  99. if Answer = "YES" then do
  100.     ColourSource PAINTPOT
  101.     NewX = X + Answer2
  102.     NewY = Y + Answer2
  103.     if NewX > (Width-1) then NewX = Width-1
  104.     if NewY > (Height-1) then NewY = Height-1
  105.     SetPot 1 255 255 255
  106.     ActivePot 1
  107.     SetDrawMode 3 Answer3
  108.     PutBrush NewX NewY
  109.     end
  110. ColourSource MULTICOLOR
  111. SetDrawMode 1
  112. PutBrush X Y
  113. AntiAlias 0
  114.  
  115. if OutPic = "SAME" then
  116.     Save InPic
  117. else
  118.     Save OutPic""right(SaveNum,3,'0')
  119.  
  120. if FrameNum = TotalNum then do
  121.     RestoreSetUp
  122.     Key "AMIGA w"
  123.     address command "wait 1"
  124.     address command "Delete >NIL: Ram:OMB"
  125.     address command "Delete >NIL: RAM:TimeLine.File"
  126.     end
  127. exit
  128.  
  129. Locate_OpalPaint:
  130.     if (POS('OpalPaint_Rexx',SHOW('Ports')) = 0)
  131.     then do
  132.         address command 'run < nil: > nil: OpalPaint:OpalPaint -q'
  133.         address command 'wait 5'
  134.     end
  135. return
  136.  
  137.  
  138. GetMotionPath:
  139.     address arexx "'call CreateHost(BFHOST,BFPORT,"MOUSESCREEN")'"
  140.     call Delay(30)
  141.     Width = 320
  142.     Height = 200
  143.     XOff = 0
  144.     YOff = 0
  145.     call Request(190,(Top+6)-14,"Select Screen Width Of Images!",,"HIRES","LORES","Batch")
  146.     if result = "OKAY" then do
  147.         Settings = "HIRES"
  148.         Width = 640
  149.         end
  150.     else Settings = ""
  151.     call Request(180,(Top+6)-14,"Select Screen Height Of Images!",,"LACE","NOLACE","Batch")
  152.     if result = "OKAY" then do
  153.         Settings = Settings"+LACE"
  154.         Height = 400
  155.         end
  156.     if Height = 400 & Width = 640 then do
  157.         call Request(185,(Top+6)-14," Select Over Scan Option!",,"OVERSCAN","REGULAR","Batch")
  158.         if result = "OKAY" then do
  159.             Settings = Settings"+OVERSCAN+AUTOSCROLL"
  160.             call Request(180,(Top+6)-14," Enter New Screen Width!","736","OKAY",,"Batch")
  161.             Width = result
  162.             XOff = 640 - Width
  163.             call Request(180,(Top+6)-14," Enter New Screen Height!","480","OKAY",,"Batch")
  164.             Height = result
  165.             YOff = 400 - Height
  166.             end
  167.         end
  168.     result = OpenScreen(YOff,3,Settings,'','MOUSESCREEN',,Width,Height,XOff)
  169.     Height = ScreenRows("MOUSESCREEN")
  170.     Width = ScreenCols("MOUSESCREEN")
  171.     idcmp     = 'CLOSEWINDOW+GADGETUP+MOUSEMOVE+MOUSEBUTTONS'
  172.     flags     = 'BORDERLESS+BACKDROP+REPORTMOUSE'
  173.     call OpenWindow(BFHOST, 0, 0, Width, Height, idcmp, flags, )
  174.     call ShowTitle("MOUSESCREEN",0)
  175.     call ModifyHost(BFHOST, MOUSEMOVE, "%l %x %y")
  176.     call ModifyHost(BFHOST, MOUSEBUTTONS, "%b %x %y")
  177.     call AddGadget(BFHOST,15,8,"OK"," OKAY ","OK")
  178.     SetAPen(BFHOST,1)
  179.     SetDrMd(BFHOST,JAM2)
  180.     call Move(BFHOST,0,Height%2)  
  181.     call Draw(BFHOST,Width,Height%2)
  182.     call Move(BFHOST,Width%2,0)  
  183.     call Draw(BFHOST,Width%2,Height)
  184.     call Move(BFHOST,0,0)  
  185.     call Draw(BFHOST,0,Height)
  186.     call Move(BFHOST,0,0)  
  187.     call Draw(BFHOST,Width,0)
  188.     call Move(BFHOST,Width-1,0)  
  189.     call Draw(BFHOST,Width-1,Height)
  190.     call Move(BFHOST,0,Height-1)  
  191.     call Draw(BFHOST,Width,Height-1)
  192.     call ActivateWindow(BFHOST)
  193.     call Request((Width-304)%2,(Height-60)%2,"Draw Line By Moving The Mouse.\Click Mouse To Change Direction.\Click OKAY When You Are Done.",,"OK",,"MOUSESCREEN")
  194.     xpos = 0
  195.     ypos = 0
  196.     xm = -1
  197.     ym = -1
  198.     quitflag = 0
  199.     Start = 0
  200.     i = 0
  201.     call openport(BFPORT)
  202.     do until quitflag = 1 
  203.       call waitpkt(BFPORT)
  204.       packet = getpkt(BFPORT)
  205.       if packet ~= null() then do
  206.         cmd = getarg(packet) 
  207.         call reply(packet,0)
  208.         if cmd = OK then do
  209.            call Move(BFHOST,xpos,ypos)
  210.            call Draw(BFHOST,xm,ym)
  211.            call ImageOK
  212.            end
  213.        else do
  214.              parse var cmd button x y
  215.              if (button == 'MOUSEMOVE' & Start > 0) then do
  216.             call Move(BFHOST,xpos,ypos)
  217.                 call Draw(BFHOST,xm,ym)
  218.                 xm = x
  219.             ym = y
  220.             call SetDrMd(BFHOST,COMPLEMENT)
  221.             call Move(BFHOST,xpos,ypos)  
  222.             call Draw(BFHOST,xm,ym)
  223.              end
  224.              else if button == 'SELECTDOWN' then do
  225.             Start = Start + 1
  226.             if Start = 1 then do
  227.             xpos = x
  228.             ypos = y
  229.             i = i + 1
  230.             XPosition.i = xpos
  231.             YPosition.i = ypos
  232.                     xm = x
  233.                   ym = y
  234.                      call SetDrMd(BFHOST,COMPLEMENT)
  235.                 call Move(BFHOST,xpos,ypos)  
  236.                 call Draw(BFHOST,xm,ym)
  237.             call PrintText
  238.             end
  239.              end
  240.          else if(button == 'SELECTUP') then do 
  241.             i = i + 1
  242.             if x = Width - 1 then x = Width
  243.             if y = Height - 1 then y = Height
  244.             XPosition.i = x
  245.             YPosition.i = y
  246.             call PrintText
  247.                    xpos = x
  248.                ypos = y
  249.             end
  250.              end
  251.       end
  252.    end
  253.    call CloseWindow(BFHOST)
  254.    result = CloseScreen('MOUSESCREEN')
  255.    call ClosePort(BFPORT)
  256. return
  257.  
  258. AbortIt:
  259.     call CloseWindow(BFHOST)
  260.     result = CloseScreen('MOUSESCREEN')
  261.     call ClosePort(BFPORT)
  262.     call Request(200,(Top+36)-14,"Process Has Been Cancelled\Please Abort Script!!",,"OK",,"Batch")
  263.     address command "Wait 2"
  264.     exit
  265. return
  266.     
  267.  
  268. ImageOK:
  269.     call Request((Width-232)/2,(Height-70)/2,"Is The Time Line Correct?",,"OK","CANCEL","MOUSESCREEN")
  270.     if result = "OKAY" then do
  271.         quitflag = 1
  272.     call open OutData,"RAM:TimeLine.File",'W'
  273.     do x = 2 to i
  274.     call writeln OutData,XPosition.x" "YPosition.x
  275.     end
  276.     call close OutData
  277.         end
  278.     else do
  279.         xpos = 0
  280.         ypos = 0
  281.         xm = -1
  282.         ym = -1
  283.         Start = 0
  284.         i = 0
  285.         call BackFill(BFHOST)
  286.         call RefreshGadgets(BFHOST)
  287.         SetAPen(BFHOST,1)
  288.         SetDrMd(BFHOST,JAM2)
  289.         call Move(BFHOST,0,Height/2)  
  290.         call Draw(BFHOST,Width,Height/2)
  291.         call Move(BFHOST,Width/2,0)  
  292.         call Draw(BFHOST,Width/2,Height)
  293.         call Move(BFHOST,0,0)  
  294.         call Draw(BFHOST,0,Height)
  295.         call Move(BFHOST,0,0)  
  296.         call Draw(BFHOST,Width,0)
  297.         call Move(BFHOST,Width-1,0)  
  298.         call Draw(BFHOST,Width-1,Height)
  299.         call Move(BFHOST,0,Height-1)  
  300.         call Draw(BFHOST,Width,Height-1)
  301.         end
  302. return
  303.  
  304. PrintText:
  305.     SetAPen(BFHOST,1)
  306.     SetDrMd(BFHOST,JAM2)
  307.     call Move(BFHOST,85,16)
  308.     YText = strip(y)
  309.     call Text(BFHOST,"Key Frame #"right(i-1,3,'0')" X="right(x,3,'0')"  Y="right(YText,3,'0'))
  310.     SetAPen(BFHOST,2)
  311.     SetDrMd(BFHOST,JAM1)
  312. return
  313.  
  314. GetXYCords:
  315.     i = 0
  316.     call open KeyData,"RAM:TimeLine.File",'R'
  317.     do until eof(KeyData)
  318.         i = i + 1
  319.         line = readln(KeyData)
  320.         parse var line XCord.i' 'YCord.i
  321.         end
  322.     call close KeyData
  323.     TotalKey = i-2
  324.     NumKey = (TotalNum/TotalKey)
  325.     FirstNum = ((NumKey - (NumKey-(FrameNum-1)))%NumKey)+1
  326.     SecNum = FirstNum+1
  327.     if FirstNum = TotalKey then do
  328.         NumKey = NumKey - 1
  329.         NewNum = (((FrameNum-((FirstNum-1)*NumKey)))-(TotalKey-1))
  330.         end
  331.     else 
  332.         NewNum = ((FrameNum-((FirstNum-1)*NumKey)))
  333.     X1 = XCord.FirstNum
  334.     Y1 = YCord.FirstNum
  335.     X2 = XCord.SecNum
  336.     Y2 = YCord.SecNum
  337.     if X2 < X1 then do
  338.         DiffX = -((X1-X2)/(NumKey))
  339.         end
  340.     else do
  341.         DiffX = ((X2-X1)/(NumKey))
  342.         end
  343.     if Y2 < Y1 then do
  344.         DiffY = -((Y1-Y2)/(NumKey))
  345.         end
  346.     else do
  347.         DiffY = ((Y2-Y1)/(NumKey))
  348.         end
  349.     X = (X1 + (DiffX*NewNum))-DiffX
  350.     Y = (Y1 + (DiffY*NewNum))-DiffY
  351.     X = X % 1
  352.     Y = Y % 1
  353. return
  354.